﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Office = Microsoft.Office.Core;
using System.Data;
using SharePointListSync.Actions.Controls; 

namespace SharePointListSync
{
   public class VOlistDetails
    {

       public SharePointListDetails.SPConnectionsRow SelecteConnectionRow; 
       public string ViewID { get; set; }
       public string ViewName { get; set; }

       public string ContentTypeID { get; set; }
       public string ContentTypeName { get; set; }

       public string ListName { get; set; }
       public string ListID { get; set; }

       public string WebURL { get; set; }
       public string WebID { get; set; }

       public int RowLimit = -1; 

        public Dictionary<string, string> ColumnToShow = new Dictionary<string, string>();
       

       public string QueryInnerString { get; set; }

       public string ViewFieldsInnerString { get; set; }
       
       public bool IsView {get ; set;}

       public VOlistDetails()
       {
 
       }



       public VOlistDetails(SharePointListDetails.SPConnectionsRow selecteConnectionRow,
           string ViewComboBoxSelectedItem,
           string  CTComboBoxSelectedItem, 
           Dictionary<string, string> selectedColumn,
           bool isView, string _nubberOFresult, string QueryFieldInnerExpresion)
      
       {

           SelecteConnectionRow = selecteConnectionRow; 
           
           WebURL = selecteConnectionRow.WebURL;
           WebID = selecteConnectionRow.WebID;

           ListName = selecteConnectionRow.ListName;
           ListID = selecteConnectionRow.ListID;

           try
           {
               RowLimit = int.Parse(_nubberOFresult);
           }
           catch
           {
               
           }
           IsView = isView;
           
            if (!string.IsNullOrEmpty(QueryFieldInnerExpresion))
           {
               QueryInnerString = QueryFieldInnerExpresion;            
           }

            if (selectedColumn != null)
            {
                ColumnToShow = selectedColumn;
                ColumnToShow.Add("ListItemID", "ID");
            }
           string tempStr;
           if (IsView)
           {
               Globals.ThisWorkbook.mACBody.mACListSelector.AllViews.TryGetValue(ViewComboBoxSelectedItem, out tempStr);
               ViewID = tempStr;
               ViewName = ViewComboBoxSelectedItem;
               DataManager odatamanager = new DataManager();
               ColumnToShow = odatamanager.GetAllColumnofView(ListName, ViewID, WebURL);
               ColumnToShow.Add("ListItemID", "ID");
           }
           
           tempStr = string.Empty;
           if (CTComboBoxSelectedItem != "None")
           {
               Globals.ThisWorkbook.mACBody.mACListSelector.allCT.TryGetValue(CTComboBoxSelectedItem, out tempStr);
               ContentTypeID = tempStr;
               ContentTypeName = CTComboBoxSelectedItem;
           }

           

       }


       public void ResetBeforUse()
       {

           SelecteConnectionRow = null;
           ViewID = null;
           ViewName = null;
           ContentTypeID = null;
           ContentTypeName = null;
           ListName = null;
           ListID = null;
           WebURL = null;
           WebID = null;
           ColumnToShow.Clear();
           QueryInnerString = null;
           ViewFieldsInnerString = null;
           IsView = false;
       }

    }
}
